/*
package com.itheima.多态.多态的好处和弊端;

public class Test3Polymorpic {
    public static void main(String[] args) {
        useAnimal(new Dog());
        useAnimal(new Cat());
    }

    public static void useAnimal(Animal a) {
        a.eat();

        //将a强转为Dog类型
        if (a instanceof Dog) {//判断当前a记录的对象是否是Dog类型
            Dog d = (Dog) a;   //存在ClassCastException的风险，解决方案：通过instanceof判断
            d.watchHome();
        }
    }


    abstract class Animal {
        public abstract void eat();
    }

    class Dog extends com.itheima.多态.多态的好处和弊端.Animal {
        public void eat() {
            System.out.println("狗吃肉");
        }

        public void watchHome() {
            System.out.println("看家");
        }
    }


    class Cat extends com.itheima.多态.多态的好处和弊端.Animal {
        public void eat() {
            System.out.println("猫吃鱼");
        }

    }


}


*/
